# SumOfList.py # # Description: Returns the sum of the numbers in a list. # # NOTE: This algorithm is known as a “running sum” # # Anne Lavergne # Date: Feb. 11 2024 def sumList(theList): """Returns the sum of the numbers in a list.""" # Initialize the accumulator variable to 0 # We use "0" because we are adding numbers theSum = 0 # For each number of the list for number in theList: # Add the number to the accumulator (running sum) theSum += number # Once done, return the result produced by this function: # the sum of all the numbers in the list return theSum #*** Main part of my program # Create a list aList = [1, 2, 3] # Call sumList with this list as an argument # And print its result i.e., the sum of the numbers in this list print(F"The sum of the numbers in the list {aList} is {sumList(aList)}.")